package com.yhq.spring.web.config;

import com.yhq.spring.web.aop.CalAdvice;
import com.yhq.spring.web.aop.CalInterceptor;
import com.yhq.spring.web.service.BeanAnnotationDemo;
import com.yhq.spring.web.service.CalculateService;
import com.yhq.spring.web.service.impl.CalculateServiceImpl;
import org.springframework.aop.framework.ProxyFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

/**
 * @author hqyin
 * @date 2025/5/25 12:36 PM
 */
@Configuration
public class TestConfig {
    @Bean
    public BeanAnnotationDemo beanAnnotationDemo() {
        return new BeanAnnotationDemo();
    }

    @Bean
    public CalculateService calculateService() {
        return new CalculateServiceImpl();
    }

    @Bean
    public CalAdvice calAdvice() {
        return new CalAdvice();
    }

    @Bean
    public CalInterceptor calInterceptor() {
        return new CalInterceptor();
    }

    /**
     * //测试ProxyFactoryBean
     * //        CalculateService demo = (CalculateService) applicationContext.getBean("calProxy",CalculateService.class);
     * //        System.out.println(demo.add());
     * @return
     */
    @Bean
    public ProxyFactoryBean calProxy(){
        ProxyFactoryBean calProxy = new ProxyFactoryBean();
        calProxy.setInterceptorNames("calInterceptor","calAdvice");
        calProxy.setTarget(calculateService());
        return calProxy;
    }
}
